********************************************************************************************************************************************************************************************************************
*************************************************************************************HUNGARY************************************************************************************************************************
******************************************************************************Refrigerators Freezers Program********************************************************************************************************

clear all
use "Estimation Sample.dta" 




set more off




tab energy_label_eu
encode energy_label_eu, gen(label)
egen cd=group(country date)
egen cy=group(country year)




xtset id2
**************************************************HUNGARY, 2016***************************************

		***UNIT SALES, COUNTERFACTUAL (ALL)
		preserve
		quietly{

egen cmt=group(country month treathf)
egen cmlt=group(country month energy_label_eu treathf)

reghdfe dlogunits i.presub3hf##ib1.treathf i.presub2hf##ib1.treathf i.presub1hf##ib1.treathf i.sub1hf##ib1.treathf i.sub2hf##ib1.treathf i.sub3hf##ib1.treathf i.sub4hf##ib1.treathf i.postsub1hf##ib1.treathf  mage mage2 , absorb(id2 cmt) cluster(cd) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3hf]) 	if presub3hf==1
replace xb_treat = (_b[1.presub2hf]) 	if presub2hf==1
replace xb_treat = (_b[1.presub1hf]) 	if presub1hf==1
replace xb_treat = (_b[1.sub1hf]) 		if sub1hf==1
replace xb_treat = (_b[1.sub2hf]) 		if sub2hf==1
replace xb_treat = (_b[1.sub3hf]) 		if sub3hf==1
replace xb_treat = (_b[1.sub4hf]) 		if sub4hf==1
replace xb_treat = (_b[1.postsub1hf]) 	if postsub1hf==1
*replace xb_treat = (_b[1.postsub2hf]) 	if postsub2hf==1
*replace xb_treat = (_b[1.postsub3hf]) 	if postsub3hf==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  

 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treathf==1
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3hf presub2hf presub1hf sub1hf sub2hf sub3hf sub4hf postsub1hf postsub2hf postsub3hf, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1hf==1
*replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2hf==1
*replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3hf==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1hf==1
*replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2hf==1
*replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3hf==1
 
 
 
 egen sumyhat3=sum(units) if (sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1) 
 egen sumyhat4=sum(yhat3) if (sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1)
 
 * check with Figure 2)*
 
 *twoway line  yhat4 date if (presub1hf==1|presub2hf==1|presub3hf==1)|(sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1)|(postsub1hf==1|postsub2hf==1|postsub3hf==1)

}
		sum sumyhat3 sumyhat4
		restore

		***UNIT SALES, COUNTERFACTUAL (A+++)
		preserve
		quietly{


egen cmt=group(country month treathf)
egen cmlt=group(country month energy_label_eu treathf)


reghdfe dlogunits i.presub3hf##ib1.treathf##ib4.label i.presub2hf##ib1.treathf##ib4.label i.presub1hf##ib1.treathf##ib4.label i.sub1hf##ib1.treathf##ib4.label i.sub2hf##ib1.treathf##ib4.label i.sub3hf##ib1.treathf##ib4.label i.sub4hf##ib1.treathf##ib4.label i.postsub1hf##ib1.treathf##ib4.label  mage mage2  , absorb(id2 cmlt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3hf]) 	if presub3hf==1
replace xb_treat = (_b[1.presub2hf]) 	if presub2hf==1
replace xb_treat = (_b[1.presub1hf]) 	if presub1hf==1
replace xb_treat = (_b[1.sub1hf]) 		if sub1hf==1
replace xb_treat = (_b[1.sub2hf]) 		if sub2hf==1
replace xb_treat = (_b[1.sub3hf]) 		if sub3hf==1
replace xb_treat = (_b[1.sub4hf]) 		if sub4hf==1
replace xb_treat = (_b[1.postsub1hf]) 	if postsub1hf==1
*replace xb_treat = (_b[1.postsub2hf]) 	if postsub2hf==1
*replace xb_treat = (_b[1.postsub3hf]) 	if postsub3hf==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  

 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treathf==1 & energy_label_eu=="A+++"
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3hf presub2hf presub1hf sub1hf sub2hf sub3hf sub4hf postsub1hf postsub2hf postsub3hf, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1hf==1
*replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2hf==1
*replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3hf==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1hf==1
*replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2hf==1
*replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3hf==1
 
 
 
 egen sumyhat3=sum(units) if (sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1) 
 egen sumyhat4=sum(yhat3) if (sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1)
 
 * check with Figure 2)*
 
 twoway line  yhat4 date if (presub1hf==1|presub2hf==1|presub3hf==1)|(sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1)|(postsub1hf==1|postsub2hf==1|postsub3hf==1)

}
		sum sumyhat3 sumyhat4
		restore

		***UNIT SALES, COUNTERFACTUAL (A++)
		preserve
		quietly{
egen cmt=group(country month treathf)
egen cmlt=group(country month energy_label_eu treathf)

reghdfe dlogunits i.presub3hf##ib1.treathf##ib3.label i.presub2hf##ib1.treathf##ib3.label i.presub1hf##ib1.treathf##ib3.label i.sub1hf##ib1.treathf##ib3.label i.sub2hf##ib1.treathf##ib3.label i.sub3hf##ib1.treathf##ib3.label i.sub4hf##ib1.treathf##ib3.label i.postsub1hf##ib1.treathf##ib3.label  mage mage2  , absorb(id2 cmlt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3hf]) 	if presub3hf==1
replace xb_treat = (_b[1.presub2hf]) 	if presub2hf==1
replace xb_treat = (_b[1.presub1hf]) 	if presub1hf==1
replace xb_treat = (_b[1.sub1hf]) 		if sub1hf==1
replace xb_treat = (_b[1.sub2hf]) 		if sub2hf==1
replace xb_treat = (_b[1.sub3hf]) 		if sub3hf==1
replace xb_treat = (_b[1.sub4hf]) 		if sub4hf==1
replace xb_treat = (_b[1.postsub1hf]) 	if postsub1hf==1
*replace xb_treat = (_b[1.postsub2hf]) 	if postsub2hf==1
*replace xb_treat = (_b[1.postsub3hf]) 	if postsub3hf==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  

 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treathf==1 & energy_label_eu=="A++"
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3hf presub2hf presub1hf sub1hf sub2hf sub3hf sub4hf postsub1hf postsub2hf postsub3hf, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1hf==1
*replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2hf==1
*replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3hf==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1hf==1
*replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2hf==1
*replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3hf==1
 
 
 
 egen sumyhat3=sum(units) if (sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1) 
 egen sumyhat4=sum(yhat3) if (sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1)
 
 * check with Figure 2)*
 
 twoway line  yhat4 date if (presub1hf==1|presub2hf==1|presub3hf==1)|(sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1)|(postsub1hf==1|postsub2hf==1|postsub3hf==1)


 }
		sum sumyhat3 sumyhat4
		restore

		***UNIT SALES, COUNTERFACTUAL (A+)
		preserve
		quietly{
egen cmt=group(country month treathf)
egen cmlt=group(country month energy_label_eu treathf)

reghdfe dlogunits i.presub3hf##ib1.treathf##ib2.label i.presub2hf##ib1.treathf##ib2.label i.presub1hf##ib1.treathf##ib2.label i.sub1hf##ib1.treathf##ib2.label i.sub2hf##ib1.treathf##ib2.label i.sub3hf##ib1.treathf##ib2.label i.sub4hf##ib1.treathf##ib2.label i.postsub1hf##ib1.treathf##ib2.label  mage mage2  , absorb(id2 cmlt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3hf]) 	if presub3hf==1
replace xb_treat = (_b[1.presub2hf]) 	if presub2hf==1
replace xb_treat = (_b[1.presub1hf]) 	if presub1hf==1
replace xb_treat = (_b[1.sub1hf]) 		if sub1hf==1
replace xb_treat = (_b[1.sub2hf]) 		if sub2hf==1
replace xb_treat = (_b[1.sub3hf]) 		if sub3hf==1
replace xb_treat = (_b[1.sub4hf]) 		if sub4hf==1
replace xb_treat = (_b[1.postsub1hf]) 	if postsub1hf==1
*replace xb_treat = (_b[1.postsub2hf]) 	if postsub2hf==1
*replace xb_treat = (_b[1.postsub3hf]) 	if postsub3hf==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  

 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treathf==1 & energy_label_eu=="A+"
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3hf presub2hf presub1hf sub1hf sub2hf sub3hf sub4hf postsub1hf postsub2hf postsub3hf, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4hf==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1hf==1
*replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2hf==1
*replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3hf==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4hf==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1hf==1
*replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2hf==1
*replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3hf==1
 
 
 
 egen sumyhat3=sum(units) if (sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1) 
 egen sumyhat4=sum(yhat3) if (sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1)
 
 * check with Figure 2)*
 
 twoway line  yhat4 date if (presub1hf==1|presub2hf==1|presub3hf==1)|(sub1hf==1|sub2hf==1|sub3hf==1|sub4hf==1)|(postsub1hf==1|postsub2hf==1|postsub3hf==1)


 }
		sum sumyhat3 sumyhat4
		restore


**************************************************HUNGARY, 2015***************************************

		***UNIT SALES, COUNTERFACTUAL (ALL)
		preserve
		quietly{

egen cmt=group(country month treath)
egen cmlt=group(country month energy_label_eu treath)

reghdfe dlogunits i.presub3h##ib1.treath i.presub2h##ib1.treath i.presub1h##ib1.treath i.sub1h##ib1.treath i.sub2h##ib1.treath i.sub3h##ib1.treath i.sub4h##ib1.treath i.postsub1h##ib1.treath i.postsub2h##ib1.treath i.postsub3h##ib1.treath mage mage2  if country!="Croatia", absorb(id2 cmt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3h]) 	if presub3h==1
replace xb_treat = (_b[1.presub2h]) 	if presub2h==1
replace xb_treat = (_b[1.presub1h]) 	if presub1h==1
replace xb_treat = (_b[1.sub1h]) 		if sub1h==1
replace xb_treat = (_b[1.sub2h]) 		if sub2h==1
replace xb_treat = (_b[1.sub3h]) 		if sub3h==1
replace xb_treat = (_b[1.sub4h]) 		if sub3h==1
replace xb_treat = (_b[1.postsub1h]) 	if postsub1h==1
replace xb_treat = (_b[1.postsub2h]) 	if postsub2h==1
replace xb_treat = (_b[1.postsub3h]) 	if postsub3h==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  


 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treath==1
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3h presub2h presub1h sub1h sub2h sub3h sub4h postsub1h postsub2h postsub3h, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3h==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3h==1
 
 
 
 egen sumyhat3=sum(units) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 egen sumyhat4=sum(yhat3) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 
 * check with Figure 2)*
 
 *twoway line  yhat4 date if (presub1h==1|presub2h==1|presub3h==1)|(sub1h==1|sub2h==1|sub3h==1|sub4h==1)|(postsub1h==1|postsub2h==1|postsub3h==1)

 * This is the baseline sales in all program months*
 }
		sum sumyhat3 sumyhat4
		restore

		***UNIT SALES, COUNTERFACTUAL (A+++)
		preserve
		quietly{
egen cmt=group(country month treath)
egen cmlt=group(country month energy_label_eu treath)

reghdfe dlogunits i.presub3h##ib1.treath##ib4.label i.presub2h##ib1.treath##ib4.label i.presub1h##ib1.treath##ib4.label i.sub1h##ib1.treath##ib4.label i.sub2h##ib1.treath##ib4.label i.sub3h##ib1.treath##ib4.label i.sub4h##ib1.treath##ib4.label i.postsub1h##ib1.treath##ib4.label i.postsub2h##ib1.treath##ib4.label i.postsub3h##ib1.treath##ib4.label mage mage2  if country!="Croatia", absorb(id2 cmlt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3h]) 	if presub3h==1
replace xb_treat = (_b[1.presub2h]) 	if presub2h==1
replace xb_treat = (_b[1.presub1h]) 	if presub1h==1
replace xb_treat = (_b[1.sub1h]) 		if sub1h==1
replace xb_treat = (_b[1.sub2h]) 		if sub2h==1
replace xb_treat = (_b[1.sub3h]) 		if sub3h==1
replace xb_treat = (_b[1.sub4h]) 		if sub3h==1
replace xb_treat = (_b[1.postsub1h]) 	if postsub1h==1
replace xb_treat = (_b[1.postsub2h]) 	if postsub2h==1
replace xb_treat = (_b[1.postsub3h]) 	if postsub3h==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  


 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treath==1 & energy_label_eu=="A+++"
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3h presub2h presub1h sub1h sub2h sub3h sub4h postsub1h postsub2h postsub3h, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3h==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3h==1
 
 
 
 egen sumyhat3=sum(units) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 egen sumyhat4=sum(yhat3) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 
 * check with Figure 2)*
 
 *twoway line  yhat4 date if (presub1h==1|presub2h==1|presub3h==1)|(sub1h==1|sub2h==1|sub3h==1|sub4h==1)|(postsub1h==1|postsub2h==1|postsub3h==1)

 * This is the baseline sales in all program months*
 }
		sum sumyhat3 sumyhat4
		restore

		***UNIT SALES, COUNTERFACTUAL (A+++, NON-SUBSIDIZED)
		preserve 
		quietly{

egen cmt=group(country month treath)
egen cmlt=group(country month energy_label_eu treath)


reghdfe dlogunits i.presub3h##i.treath##ib4.label i.presub2h##i.treath##ib4.label i.presub1h##i.treath##ib4.label i.sub1h##i.treath##ib4.label i.sub2h##i.treath##ib4.label i.sub3h##i.treath##ib4.label i.sub4h##i.treath##ib4.label i.postsub1h##i.treath##ib4.label i.postsub2h##i.treath##ib4.label i.postsub3h##i.treath##ib4.label mage mage2  if country!="Croatia", absorb(id2 cmlt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3h]) 	if presub3h==1
replace xb_treat = (_b[1.presub2h]) 	if presub2h==1
replace xb_treat = (_b[1.presub1h]) 	if presub1h==1
replace xb_treat = (_b[1.sub1h]) 		if sub1h==1
replace xb_treat = (_b[1.sub2h]) 		if sub2h==1
replace xb_treat = (_b[1.sub3h]) 		if sub3h==1
replace xb_treat = (_b[1.sub4h]) 		if sub3h==1
replace xb_treat = (_b[1.postsub1h]) 	if postsub1h==1
replace xb_treat = (_b[1.postsub2h]) 	if postsub2h==1
replace xb_treat = (_b[1.postsub3h]) 	if postsub3h==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  


 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treath==0 & energy_label_eu=="A+++"
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3h presub2h presub1h sub1h sub2h sub3h sub4h postsub1h postsub2h postsub3h, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3h==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3h==1
 
 
 
 egen sumyhat3=sum(units) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 egen sumyhat4=sum(yhat3) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 
 * check with Figure 2)*
 
 *twoway line  yhat4 date if (presub1hw==1|presub2hw==1|presub3hw==1)|(sub1hw==1|sub2hw==1|sub3hw==1|sub4hw==1)|(postsub1hw==1|postsub2hw==1|postsub3hw==1)

 * This is the baseline sales in all program months*
 
 }
		sum sumyhat3 sumyhat4
		restore

		***UNIT SALES, COUNTERFACTUAL (A++)
		preserve
		quietly{

egen cmt=group(country month treath)
egen cmlt=group(country month energy_label_eu treath)

reghdfe dlogunits i.presub3h##ib1.treath##ib3.label i.presub2h##ib1.treath##ib3.label i.presub1h##ib1.treath##ib3.label i.sub1h##ib1.treath##ib3.label i.sub2h##ib1.treath##ib3.label i.sub3h##ib1.treath##ib3.label i.sub4h##ib1.treath##ib3.label i.postsub1h##ib1.treath##ib3.label i.postsub2h##ib1.treath##ib3.label i.postsub3h##ib1.treath##ib3.label mage mage2  if country!="Croatia", absorb(id2 cmlt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3h]) 	if presub3h==1
replace xb_treat = (_b[1.presub2h]) 	if presub2h==1
replace xb_treat = (_b[1.presub1h]) 	if presub1h==1
replace xb_treat = (_b[1.sub1h]) 		if sub1h==1
replace xb_treat = (_b[1.sub2h]) 		if sub2h==1
replace xb_treat = (_b[1.sub3h]) 		if sub3h==1
replace xb_treat = (_b[1.sub4h]) 		if sub3h==1
replace xb_treat = (_b[1.postsub1h]) 	if postsub1h==1
replace xb_treat = (_b[1.postsub2h]) 	if postsub2h==1
replace xb_treat = (_b[1.postsub3h]) 	if postsub3h==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  


 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treath==1 & energy_label_eu=="A++"
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3h presub2h presub1h sub1h sub2h sub3h sub4h postsub1h postsub2h postsub3h, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3h==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3h==1
 
 
 
 egen sumyhat3=sum(units) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 egen sumyhat4=sum(yhat3) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 
 * check with Figure 2)*
 
 *twoway line  yhat4 date if (presub1h==1|presub2h==1|presub3h==1)|(sub1h==1|sub2h==1|sub3h==1|sub4h==1)|(postsub1h==1|postsub2h==1|postsub3h==1)

 * This is the baseline sales in all program months*
 }
		sum sumyhat3 sumyhat4
		restore

		***UNIT SALES, COUNTERFACTUAL (A+)
		preserve
		quietly{

egen cmt=group(country month treath)
egen cmlt=group(country month energy_label_eu treath)

reghdfe dlogunits  i.presub3h##ib1.treath##ib2.label i.presub2h##ib1.treath##ib2.label i.presub1h##ib1.treath##ib2.label i.sub1h##ib1.treath##ib2.label i.sub2h##ib1.treath##ib2.label i.sub3h##ib1.treath##ib2.label i.sub4h##ib1.treath##ib2.label i.postsub1h##ib1.treath##ib2.label i.postsub2h##ib1.treath##ib2.label i.postsub3h##ib1.treath##ib2.label mage mage2  if country!="Croatia", absorb(id2 cmlt) cluster(id)  residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3h]) 	if presub3h==1
replace xb_treat = (_b[1.presub2h]) 	if presub2h==1
replace xb_treat = (_b[1.presub1h]) 	if presub1h==1
replace xb_treat = (_b[1.sub1h]) 		if sub1h==1
replace xb_treat = (_b[1.sub2h]) 		if sub2h==1
replace xb_treat = (_b[1.sub3h]) 		if sub3h==1
replace xb_treat = (_b[1.sub4h]) 		if sub3h==1
replace xb_treat = (_b[1.postsub1h]) 	if postsub1h==1
replace xb_treat = (_b[1.postsub2h]) 	if postsub2h==1
replace xb_treat = (_b[1.postsub3h]) 	if postsub3h==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  


 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Hungary" & treath==1 & energy_label_eu=="A+"
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3h presub2h presub1h sub1h sub2h sub3h sub4h postsub1h postsub2h postsub3h, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2h==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3h==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2h==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3h==1
 
 
 
 egen sumyhat3=sum(units) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 egen sumyhat4=sum(yhat3) if (sub1h==1|sub2h==1|sub3h==1|sub4h==1)
 
 * check with Figure 2)*
 
 *twoway line  yhat4 date if (presub1h==1|presub2h==1|presub3h==1)|(sub1h==1|sub2h==1|sub3h==1|sub4h==1)|(postsub1h==1|postsub2h==1|postsub3h==1)

 * This is the baseline sales in all program months*
 } 
		sum sumyhat3 sumyhat4
		restore

		
**************************************************AUSTRIA, 2009**********************************************
		preserve 
		quietly{
egen cmt=group(country month treataf)

reghdfe dlogunits i.presub3af9##ib1.treataf i.presub2af9##ib1.treataf i.presub1af9##ib1.treataf i.sub1af9##ib1.treataf i.sub2af9##ib1.treataf i.sub3af9##ib1.treataf i.sub4af9##ib1.treataf i.postsub1af9##ib1.treataf i.postsub2af9##ib1.treataf i.postsub3af9##ib1.treataf  mage mage2 , absorb(id2 cmt) cluster(id) residuals(res)



predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3af9]) 	if presub3af9==1
replace xb_treat = (_b[1.presub2af9]) 	if presub2af9==1
replace xb_treat = (_b[1.presub1af9]) 	if presub1af9==1
replace xb_treat = (_b[1.sub1af9]) 		if sub1af9==1
replace xb_treat = (_b[1.sub2af9]) 		if sub2af9==1
replace xb_treat = (_b[1.sub3af9]) 		if sub3af9==1
replace xb_treat = (_b[1.sub4af9]) 		if sub4af9==1
replace xb_treat = (_b[1.postsub1af9]) 	if postsub1af9==1
replace xb_treat = (_b[1.postsub2af9]) 	if postsub2af9==1
replace xb_treat = (_b[1.postsub3af9]) 	if postsub3af9==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  

 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Austria" & treataf==1
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3af9 presub2af9 presub1af9 sub1af9 sub2af9 sub3af9 sub4af9 postsub1af9 postsub2af9 postsub3af9, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub4af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2af9==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3af9==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub4af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2af9==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3af9==1
 
 
 
 egen sumyhat3=sum(units) if (sub1af9==1|sub2af9==1|sub3af9==1|sub4af9==1)
 egen sumyhat4=sum(yhat3) if (sub1af9==1|sub2af9==1|sub3af9==1|sub4af9==1)
 
* check with Figure 2)*
 
*twoway line  yhat4 date if (presub1af9==1|presub2af9==1|presub3af9==1)|(sub1af9==1|sub2af9==1|sub3af9==1|sub4af9==1)|(postsub1af9==1|postsub2af9==1|postsub3af9==1)

}
		sum sumyhat3 sumyhat4
		restore


**************************************************AUSTRIA, 2010, FF******************************************
		preserve 
		quietly{
egen cmt=group(country month treataf)


reghdfe dlogunits i.presub3af10##ib1.treataf i.presub2af10##ib1.treataf i.presub1af10##ib1.treataf i.sub1af10##ib1.treataf i.sub2af10##ib1.treataf i.sub3af10##ib1.treataf i.postsub1af10##ib1.treataf i.postsub2af10##ib1.treataf i.postsub3af10##ib1.treataf  mage mage2 , absorb(id2 cmt) cluster(id) residuals(res)



predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3af10]) 	if presub3af10==1
replace xb_treat = (_b[1.presub2af10]) 	if presub2af10==1
replace xb_treat = (_b[1.presub1af10]) 	if presub1af10==1
replace xb_treat = (_b[1.sub1af10]) 		if sub1af10==1
replace xb_treat = (_b[1.sub2af10]) 		if sub2af10==1
replace xb_treat = (_b[1.sub3af10]) 		if sub3af10==1
replace xb_treat = (_b[1.postsub1af10]) 	if postsub1af10==1
replace xb_treat = (_b[1.postsub2af10]) 	if postsub2af10==1
replace xb_treat = (_b[1.postsub3af10]) 	if postsub3af10==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  


 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Austria" & treataf==1
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3af10 presub2af10 presub1af10 sub1af10 sub2af10 sub3af10 postsub1af10 postsub2af10 postsub3af10, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3af10==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2af10==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1af10==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1af10==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2af10==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub3af10==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1af10==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2af10==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3af10==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3af10==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2af10==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1af10==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1af10==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2af10==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub3af10==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1af10==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2af10==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3af10==1
 
 
 
 egen sumyhat3=sum(units) if (sub1af10==1|sub2af10==1|sub3af10==1)
 egen sumyhat4=sum(yhat3) if (sub1af10==1|sub2af10==1|sub3af10==1)
 
 * check with Figure 2)*
 
 twoway line  yhat4 date if (presub1af10==1|presub2af10==1|presub3af10==1)|(sub1af10==1|sub2af10==1|sub3af10==1)|(postsub1af10==1|postsub2af10==1|postsub3af10==1)

 * This is the baseline sales in all program months*
 
}
		sum sumyhat3 sumyhat4
		restore

		
**************************************************AUSTRIA, 2010, WM******************************************
		preserve
		quietly{
egen cmt=group(country month treata)


reghdfe dlogunits i.presub3a##ib1.treata i.presub2a##ib1.treata i.presub1a##ib1.treata i.sub1a##ib1.treata i.sub2a##ib1.treata i.postsub1a##ib1.treata i.postsub2a##ib1.treata i.postsub3a##ib1.treata  mage mage2 , absorb(id2 cmt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3a]) 	if presub3a==1
replace xb_treat = (_b[1.presub2a]) 	if presub2a==1
replace xb_treat = (_b[1.presub1a]) 	if presub1a==1
replace xb_treat = (_b[1.sub1a]) 		if sub1a==1
replace xb_treat = (_b[1.sub2a]) 		if sub2a==1
replace xb_treat = (_b[1.postsub1a]) 	if postsub1a==1
replace xb_treat = (_b[1.postsub2a]) 	if postsub2a==1
replace xb_treat = (_b[1.postsub3a]) 	if postsub3a==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  


 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Austria" & treata==1
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3a presub2a presub1a sub1a sub2a postsub1a postsub2a postsub3a, by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3a==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2a==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1a==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1a==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub2a==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1a==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2a==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3a==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3a==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2a==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1a==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1a==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub2a==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1a==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2a==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3a==1
 
 
 
 egen sumyhat3=sum(units) if (sub1a==1|sub2a==1)
 egen sumyhat4=sum(yhat3) if (sub1a==1|sub2a==1)
 
 * check with Figure 2)*
 
 twoway line  yhat4 date if (presub1a==1|presub2a==1|presub3a==1)|(sub1a==1|sub2a==1)|(postsub1a==1|postsub2a==1|postsub3a==1)

 * This is the baseline sales in all program months*
 }
		sum sumyhat3 sumyhat4
		restore


**************************************************CROATIA, 2015, WM******************************************
		preserve 
		drop if category=="refrigerator"
		drop if category=="freezer"
		quietly{
egen cmt=group(country month treatc)

reghdfe dlogunits i.presub3c##ib1.treatc i.presub2c##ib1.treatc i.presub1c##ib1.treatc i.sub1c##ib1.treatc i.postsub1c##ib1.treatc i.postsub2c##ib1.treatc i.postsub3c##ib1.treatc i.postsub4c##ib1.treatc i.postsub5c##ib1.treatc i.postsub6c##ib1.treatc  i.postsub7c##ib1.treatc mage mage2  if country!="Hungary" , absorb (id2 cmt) cluster(id) residuals(res)


predict xbd                  if e(sample), xbd

 
xtset id1 date
 
gen     xb_treat = (_b[1.presub3c]) 	if presub3c==1
replace xb_treat = (_b[1.presub2c]) 	if presub2c==1
replace xb_treat = (_b[1.presub1c]) 	if presub1c==1
replace xb_treat = (_b[1.sub1c]) 		if sub1c==1
replace xb_treat = (_b[1.postsub1c]) 	if postsub1c==1
replace xb_treat = (_b[1.postsub2c]) 	if postsub2c==1
replace xb_treat = (_b[1.postsub3c]) 	if postsub3c==1
replace xb_treat = (_b[1.postsub4c]) 	if postsub4c==1
replace xb_treat = (_b[1.postsub5c]) 	if postsub5c==1
replace xb_treat = (_b[1.postsub6c]) 	if postsub6c==1
replace xb_treat = (_b[1.postsub7c]) 	if postsub7c==1


gen     yhat0  =xbd+res                 if e(sample)  
gen     yhat1  =xbd+res-xb_treat        if e(sample)  
gen     yhat2  =xb_treat                if e(sample)  

 

 * focus on treated products *

 xtset id1 date
 sort id1 cmt
 keep if country=="Croatia" & treatc==1
 collapse (sum) units (mean) yhat0 yhat1 yhat2 presub3c presub2c presub1c sub1c postsub1c postsub2c postsub3c postsub4c postsub5c postsub6c postsub7c , by (date)
 
 sort date 
 tsset date

 
* computes the baseline *

gen     yhat3    = exp(log(l.units)+yhat1) if presub3c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub2c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if presub1c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if sub1c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub1c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub2c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub3c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub4c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub5c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub6c==1
replace yhat3    = exp(log(l.yhat3)+yhat1) if postsub7c==1

* computes the predicted outcome (should match Figure 2)*

gen     yhat4    = exp(log(l.units)+yhat2) if presub3c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub2c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if presub1c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if sub1c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub1c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub2c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub3c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub4c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub5c==1
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub6c==1 
replace yhat4    = exp(log(l.yhat4)+yhat2) if postsub7c==1 

 
 egen sumyhat3_1=sum(units) if (sub1c==1)
 egen sumyhat4_1=sum(yhat3) if (sub1c==1)
 
 egen sumyhat3_2=sum(units) if (postsub4c==1)
 egen sumyhat4_2=sum(yhat3) if (postsub4c==1)
 
 * check with Figure 2)*
 
*twoway line  yhat4 date if (presub1c==1|presub2c==1|presub3c==1)|(sub1c==1)|(postsub1c==1|postsub2c==1|postsub3c==1|postsub4c==1|postsub5c==1|postsub6c==1|postsub7c==1)
}
		sum sumyhat3_1 sumyhat4_1
		sum sumyhat3_2 sumyhat4_2
		restore


		
****************KiloWatt Hour Difference between Subsidized and Total Stock in Year of Subsidy***************

*********AT, 2009
**Average energy use of subsidized ref/frz in Austria in 2009
sum annual_energy_consumption if country=="Austria" & year==2009 & treataf==1

**Average energy use of the entire stock of ref/frz on the Austrian market in 2009
sum annual_energy_consumption if country=="Austria" & year==2009 & (category=="refrigerator"|category=="freezer")


*********AT, 2010, FF
**Average energy use of subsidized ref/frz in Austria in 2010
sum annual_energy_consumption if country=="Austria" & year==2010 & treataf==1

**Average energy use of the entire stock of ref/frz on the Austrian market in 2009
sum annual_energy_consumption if country=="Austria" & year==2010 & (category=="refrigerator"|category=="freezer")


*********AT, 2010, WM
**Average energy use of subsidized wm in Austria in 2010
sum annual_energy_consumption if country=="Austria" & year==2010 & treata==1

**Average energy use of the entire stock of wm on the Austrian market in 2009
sum annual_energy_consumption if country=="Austria" & year==2010 & (category=="washing machine")


*********HU, 2016
**Average energy use of subsidized ref/frz in Hungary in 2016
sum annual_energy_consumption if country=="Hungary" & year==2016 & treathf==1 & energy_label_eu=="A+++"
sum annual_energy_consumption if country=="Hungary" & year==2016 & treathf==1 & energy_label_eu=="A++"
sum annual_energy_consumption if country=="Hungary" & year==2016 & treathf==1 & energy_label_eu=="A+"

**Average energy use of the entire stock of ref/frz on the Hungarian market in 2016
sum annual_energy_consumption if country=="Hungary" & year==2016 & (category=="refrigerator"|category=="freezer")


*********HU, 2015
**Average energy use of subsidized wm in Hungary in 2015
sum annual_energy_consumption if country=="Hungary" & year==2015 & treath==1 & energy_label_eu=="A+++"
sum annual_energy_consumption if country=="Hungary" & year==2015 & treath==1 & energy_label_eu=="A++"
sum annual_energy_consumption if country=="Hungary" & year==2015 & treath==1 & energy_label_eu=="A+"

**Average energy use of the entire stock of wm on the Hungarian market in 2015
sum annual_energy_consumption if country=="Hungary" & year==2015 & (category=="washing machine")

*********HR, 2015
**Average energy use of subsidized ref/frz/wm in Croatia in 2015
sum annual_energy_consumption if country=="Croatia" & year==2015 & treatc==1 & category=="washing machine"

**Average energy use of the entire stock of ref/frz/wm on the Croatian market in 2009
sum annual_energy_consumption if country=="Croatia" & year==2015 & category=="washing machine"

